let config;
let createConfig;
const md = window.markdownit();
axios.get('../static/data/createConfig.json') //在config文件加载完后再回调运行vue
    .then(function (response) {
        createConfig = response.data;
        axios.get('../static/data/commonConfig.json') //在config文件加载完后再回调运行vue
            .then(function (response) {
                commonConfig = response.data;
                runVue();
            })
            .catch(function (error) {
                console.log(error);
            })
    })
    .catch(function (error) {
        console.log(error);
    })
// VUE脚本
const runVue = () => {
    const {ref, computed, reactive} = Vue;
    const App = {
        setup() {
            const topBars = commonConfig['topBars'];
            const previewCardButtonText = createConfig['previewCardButtonText'];
            const publishContentEntry = createConfig['publishContentEntry'];
            const editPrompt = createConfig['editPrompt'];
            const publishContentButton = createConfig['publishContentButton'];
            const userButtonText = commonConfig['userButtonText'];
            const textareaValue = ref('');
            const showDialogBox = ref(false);
            const isLogin = ref(false);
            const noteItemText = commonConfig['noteItemText'];
            const goTo = (link) => {
                window.location.href = link;
            }
            const handleKeydown = (event) => {
                if (event.key === 'Tab') {
                    event.preventDefault();
                    const textareaElement = document.querySelector('textarea');
                    const start = textareaElement.selectionStart;
                    const currentValue = textareaValue.value;
                    textareaValue.value = currentValue.slice(0, start) + '\t' + currentValue.slice(start);
                    setTimeout(() => {
                        textareaElement.setSelectionRange(start + 1, start + 1);
                        textareaElement.focus();
                    }, 1)
                }
            };
            const editTextToHtml = computed(() => {
                return md.render(textareaValue.value);
            })
            return {
                goTo,
                topBars,
                editPrompt,
                textareaValue,
                handleKeydown,
                editTextToHtml,
                showDialogBox,
                previewCardButtonText,
                publishContentEntry,
                publishContentButton,
                isLogin,
                userButtonText,
                noteItemText
            }
        },
    };
    const app = Vue.createApp(App);
    app.mount("#app");
}